#include "rx.h"
#include "globalParameters.h"
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <ctime>

using namespace std;

Rx::Rx(int id, int x, int y, GlobalParameters parameters)
{
	rxID = id;
	xPos = x,
	yPos = y;
	signal = 0;
	interference = 0;
	noise = pow(10.0,-13.0);//noise level accross the network
	slotsToGo = -1;
}

void Rx::print(){
	cout << "RX ID: " << rxID << endl;
	cout << "xPos: " << xPos << endl;
	cout << "yPos: " << yPos << endl;
	cout << "Signal: " << signal << endl;
	cout << "Interference:" << interference << endl;
	cout << "Noise: " << noise << endl;
}

int Rx::getID(){
	return rxID;
}

double Rx::getSignal(){
	return signal;
}

void Rx::setSignal(double s)
{
	if (s<0) {
	 	cout <<"wrong signal value";
		return;
	}

	signal = s;	
}

double Rx::getInterference()
{
	return interference;
}

void Rx::setInterference(double i)
{
	if (i<0) {
		cout <<"wrong interference value";
		return;
	}

 	interference = i;
}

double Rx::getNoise()
{
	return noise;
}

void Rx::setNoise(double n){
	if (n < 0) 
	{
		cout << "wrong noise value";
		return;
	}
	
	noise = n;
}

int Rx::getTransmitter(){
	return transmitter;
}

void Rx::setTransmitter(int inputTrans){
	transmitter = inputTrans;
}

int Rx::getX(){
	return xPos;
}

int Rx::getY(){
	return yPos;
}

int Rx::getId(){
	return rxID;
}

void Rx::incrementInterference(double addValue){
	interference = interference + addValue;
}

bool Rx::canReceive(GlobalParameters parameters){
	// signal(watts)/(noise(watts)+sum on interferences(watts)) is greater than the reception threshold.
	// and 
	
	if((10*log10(signal/(noise+interference))) > parameters.getReceptionThreshold()){ return true;}
	else{return false;}

	//CHANGE THIS
	//return true;
	
}

bool Rx::successOnLast(){
	return lastPacket;
}

void Rx::setSlotsToGo(int input){
	slotsToGo = input;
}

int Rx::getSlotsToGo(){
	return slotsToGo;
}

void Rx::decrementSlotsToGo(){
	slotsToGo = slotsToGo - 1;
}

void Rx::setLastPacket(bool input){
	lastPacket = input;
}
